/** 子进程 */
const exec = require('child_process').exec;
const { Print } = require('../print/print');


const cmd = (strCmd, debug = false) => {
	return new Promise((resolve, reject) => {
		exec(strCmd, function(err, stdout, stderr) {
			if (err) {
				resolve(err);
			} else if (stderr.lenght > 0) {
				resolve(new Error(stderr.toString()));
			} else {
				if (debug) {
					console.log(stdout);
					Print.success(`${strCmd} 运行命令成功`);
				}
				resolve(true);
			}
		});
	}).catch((err) => {
		Print.error(`${strCmd} 运行命令出错`);
		console.log(err);
	});
}

module.exports = {
	cmd,
};